<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('配置文件列表')" />
	<th:block th:include="include :: layout-latest-css" />
	<th:block th:include="include :: select2-css" />
</head>
<body class="gray-bg">

<div class="container-div">
	<div class="row">

		<div class="col-sm-12 search-collapse">
			<form id="searchForm">
				<div style="border: 0px solid red;width: 800px;height:32px;display: flex;">
					<div style="width:90px">
						<button type="button" class="btn btn-primary btn-sm" onclick="$.operate.openAdd(null,null,null)" >
							<i class="fa fa-plus"></i> 新增
						</button>
					</div>
					<div style="width:70px">
						<button type="button" class="btn btn-info btn-success btn-sm" onclick="release()">
							<i class="glyphicon glyphicon-send"></i> &nbsp;发布
						</button>
					</div>
					<div style="width:200px;display: inline-flex;">
						<div style="width: 70px;height: 32px;line-height: 32px;text-align: right">
							环境：
						</div>
						<div>
							<select id="envCode" name="envCode"  >
							</select>
						</div>
					</div>
					<div style="width:200px;display: inline-flex;">
						<div style="width: 70px;height: 32px;line-height: 32px;text-align: right">
							应用：
						</div>
						<div>
							<select id="appCode" name="appCode"  style="width: 100px;">
							</select>
						</div>
					</div>

					<div style="width:65px">
						<a class="btn btn-primary btn-rounded btn-sm" onclick="searchForm()"><i class="fa fa-search"></i>&nbsp;搜索</a>
					</div>



				</div>

			</form>
		</div>

		<div class="btn-group-sm" id="toolbar" role="group">
			<!--<a class="btn btn-success" onclick="$.operate.openAdd(null,null)" >
				<i class="fa fa-plus"></i> 新增
			</a>-->
		</div>

		<div class="col-sm-12 select-table table-condensed " style="height:98%;">
			<table id="bootstrap-table"></table>
		</div>
	</div>
</div>

<th:block th:include="include :: footer" />
<th:block th:include="include :: select2-js" />
	<script th:inline="javascript">
		var editFlag ;
		var removeFlag ;
		var prefix = ctx + "m/system/config";


		$(function() {

			common.loadEnv("envCode","",true);
			$('#envCode').select2({
				allowClear: false,
				width:"120",
				height:"30"
			});
			$("#envCode").on("change",function () {
				searchPre();
			});



			common.loadApp("appCode","",true);
			$('#appCode').select2({
				allowClear: false,
				width:"120"
			});
			var appCode = $("#appCode").val();


		    var options = {
		        url: prefix + "/page",
		        createUrl: prefix + "/add",
		        updateUrl: prefix + "/edit?id={id}",
		        removeUrl: prefix + "/deleteById?id={id}",
		        exportUrl: prefix + "/export",
				detailUrl:  prefix + "/edit?id={id}",
		        modalName: "",
				sortName: "createDate",
				sortOrder: "desc",
				method:"get",
				queryParams: queryParams,
		        columns: [
		        {
		            field: 'fileName',
		            title: '文件名称',
					align: 'center'
		        },
				{
					field: 'fileType',
					title: '文件类型',
					align: 'center'
				},
				{
					field: 'status',
					title: '状态',
					align: 'center',
					formatter: function(value, row, index) {
						var status=value;
						if (status == "4") {
							return "已发布";
						} else if (status==3){
							return "<span style='color:red;font-weight: bold;'>已删除</span>";
						} else if (status==2){
							return "<span style='color:red;font-weight: bold;'>已修改</span>";
						}else if (status==1){
							return "<span style='color:red;font-weight: bold;'>新增</span>";
						}else if (status==5){
							return "<span style='color:red;font-weight: bold;'>回滚</span>";
						}
						return "";
					}
				},
				{
					field: 'modifier',
					title: '操作人',
					align: "center"
				},
				{
					field: 'fileDesc',
					title: '描述',
					align: "center"
				},
				{
					field: 'createDate',
					title: '创建时间',
					align: "center"
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		                var actions = [];
						actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.id + '\',null,null)"><i class="glyphicon glyphicon-eye-open"></i>查看</a> ');
						actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="clone(\'' + row.id + '\')"><i class="glyphicon glyphicon-transfer"></i>克隆 </a> ');
		                actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\',null,null)"><i class="fa fa-edit"></i>编辑</a> ');
						actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
						if (row.status==2 || row.status==3){
							actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="undel(\'' + row.id + '\')"><i class="glyphicon glyphicon-star-empty"></i>撤销</a> ');
						}

						return actions.join('');
		            }
		        }]
		    };
		    $.table.init(options);

		});
		function queryParams(params) {
			var search = $.table.queryParams(params);
			return search;
		}

		function searchForm() {
			$.table.search('searchForm', 'bootstrap-table');
		}
		function undel(id) {
			$.operate.post2(prefix+"/unDel",{id:id},function (data) {
				$.operate.ajaxSuccess(data);
			})
		}
		function clone(id) {
			$.modal.open("克隆",prefix+"/clone?id="+id,null,null,null);
		}

		function release() {
			var envCode = $("#envCode").val();
			if (!envCode){
				$("#envCode").focus();
				$.modal.msgError("请选择要发布的环境");
				return;
			}
			var appCode = $("#appCode").val();
			if (!appCode){
				$("#appCode").focus();
				$.modal.msgError("请选择要发布的应用");
				return;
			}
			var msg = "["+envCode+"环境]"+"["+appCode+"应用]";


			$.modal.confirm("确定要发布"+msg,function () {
				var url = prefix + "/releaseConfig";
				var data = $("#searchForm").serializeJson();
				$.operate.post2(url, data,function (r) {
					$.operate.successCallback(r);
					searchForm();
				});
			})

		}
	</script>
</body>
</html>